package util

import (
	"github.com/jinzhu/gorm"
	_ "github.com/go-sql-driver/mysql"

	"shop_be/model"
)

var Db *gorm.DB

func Dbinit() *gorm.DB {
	db, err := gorm.Open("mysql", "root:@/shop?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		panic(err)
	}

	db.AutoMigrate(&model.User{})
	db.AutoMigrate(&model.Product{})
	db.AutoMigrate(&model.Order{})
	db.AutoMigrate(&model.Shopcart{})

	Db = db
	return db
}
